package com.example.zzm.yuejian03.Activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.zzm.yuejian03.Bean.collectBean;
import com.example.zzm.yuejian03.Listener.TListener;
import com.example.zzm.yuejian03.Model.MyModel;
import com.example.zzm.yuejian03.Model.updatePasswordModel;
import com.example.zzm.yuejian03.R;

public class updatePassActivity extends AppCompatActivity {
    private Button button27;
    private TextView textView11;
    private EditText editText8,editText9;
    private int uid;
    private SharedPreferences sp;

    public void  onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.updatepass);
        initView();
        initEvent();
        sp = getSharedPreferences("userInfo", MODE_PRIVATE);
        uid = sp.getInt("user_id", 1);

    }

    TListener<collectBean> listener = new TListener<collectBean>() {
        @Override
        public void onResponse(collectBean collectBean) {
            Toast.makeText(updatePassActivity.this,"修改密码成功", Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(updatePassActivity.this,LoginActivity.class);
            startActivity(intent);
            finish();
        }

        @Override
        public void onFail(String msg) {

        }
    };

    private void initEvent() {
        textView11.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        button27.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String newpwd = editText8.getText().toString();
                String againpwd = editText9.getText().toString();
                if(newpwd==""||newpwd==null||againpwd==""||againpwd==null){
                    Toast.makeText(updatePassActivity.this,"输入不能为空", Toast.LENGTH_SHORT).show();
                }else if(!newpwd.equals(againpwd)){
                    editText9.setError("两次输入不一致");
                }else {
                    updatePasswordModel model= new updatePasswordModel();
                    model.getupdatePassword(uid,newpwd,listener);
                }
            }
        });
    }

    private void initView() {
        textView11 = (TextView)findViewById(R.id.textView11);
        button27 = (Button)findViewById(R.id.button27);
        editText8 = (EditText)findViewById(R.id.editText8);
        editText9 = (EditText)findViewById(R.id.editText9);
    }
}
